package com.zr.gdms.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zr.gdms.dao.ShuRuSelectStudentdao;
import com.zr.gdms.model.Student;
import com.zr.gdms.util.JDBCUtil;

public class ShuRuSelectStudentdaoimpl implements ShuRuSelectStudentdao {

	@Override
	public List<Student> getShuRuSdepartStudent(String name, int page, int rows) {
		// TODO Auto-generated method stub
		List<Student> st1=new ArrayList<Student>();
		StringBuffer sq1=new StringBuffer();
		sq1.append(" select * from student where student.sdepart=?");
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst1=con.prepareStatement(sq1.toString());
			pst1.setString(1, name);
			ResultSet rs1=pst1.executeQuery();
			while(rs1.next()){
				Student ss1=new Student();
				ss1.setSid(rs1.getInt("sid"));
				ss1.setSname(rs1.getString("sname"));
				ss1.setSage(rs1.getString("sage"));			
				ss1.setSsex(rs1.getString("ssex"));
				ss1.setSdepart(rs1.getString("sdepart"));
				ss1.setStel(rs1.getString("stel"));		
				ss1.setSstate(rs1.getString("sstate"));			
				st1.add(ss1);				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return st1;
	}

	@Override
	public int getStudentsCount() {
		// TODO Auto-generated method stub
		int count=0;
		StringBuffer sq1=new StringBuffer();
		sq1.append(" SELECT COUNT(sid) AS scount");
		sq1.append(" from student");	
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sq1.toString());	
			ResultSet rt=pst.executeQuery();
			if(rt.next()){
				count=rt.getInt("scount");	
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
}
